<template>
  <div class="devicePreload-remove-component">
    <el-dialog
      v-if="modelValue.visible"
      v-model="modelValue.visible"
      title="确认完成部署"
      width="400px"
    >
      <div>
        <div>
          确认已经完成了该门店
          <span style="color: green"> ({{ modelValue.form.storeName }}) </span>
          的机器部署吗?
        </div>
        <div>
          部署的机器编码为：
          <el-tag
            v-for="item in modelValue.deviceList"
            :key="item"
            style="margin-left: 2px"
          >
            {{ item }}
          </el-tag>
        </div>
      </div>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="cancel">取消</el-button>
          <el-button type="primary" @click="ensure"> 确定 </el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>
<script setup lang="ts">
//提示弹框。
import { ElMessage } from 'element-plus'
//请求对应的删除接口。
import {
  batchRemoveDevicePreload,
  updateDevicePreload,
} from '@/api/dms-device-preload.api'
//获取从父组件传来的数据。
const props = defineProps(['modelValue'])

const ensure = () => {
  let id = props.modelValue.curSelectRow.id
  updateDevicePreload({
    id,
    deployStatus: 1,
  })
    .then((res) => {
      cancel()
      ElMessage({
        message: '提交成功',
        type: 'success',
      })

      if (props.modelValue.refreshDataList) {
        props.modelValue.refreshDataList()
      }
    })
    .catch((err) => {
      cancel()
      ElMessage({
        message: err.msg || err,
        type: 'error',
      })
    })
}

const cancel = () => {
  props.modelValue.visible = false
}
</script>
<style lang="scss" scoped></style>
